<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 迭代器 ，可以调取next()方法，下一步执行
        // 内置可迭代对象  ：entries keys  values
        let arr = ['张三', '李四', '王五'];
        console.log(arr);
        // // var iterator = arr[Symbol.iterator]();
        var iterator = arr.entries();
        // // var iterator = arr.keys();
        // var iterator = arr.values();
        // console.log(iterator);
        // console.log(iterator.next());
        // console.log(iterator.next());
        // console.log(iterator.next());
        // console.log(iterator.next());

        for (let [key,val] of arr) {
            console.log(key,val);
        }
        for (let [key,val] of iterator) {
            console.log(key,val);
        }

        // 生成器 generator
        function *myIterator() {
            yield  'aa'
            yield  'bb'
            yield  'cc'
        }
        let iterator1 = myIterator();
        // console.log(iterator1.next());
        // console.log(iterator1.next());
        // console.log(iterator1.next());
        // console.log(iterator1.next());

        for ( let [key,val] of iterator1) {
            console.log(key, val);
        }
        for (let val of iterator1) {
            console.log( val);
        }
    </script>
</body>
</html>